<?php
include "sql.php";
include "time.php";

switch($_GET['type'])
{
    case 10:
    {
        $type='五山·所有提案';
        break;
    }
	case 11:
    {
        $type='五山·校园环境';
        break;
    }
	case 12:
    {
        $type='五山·学生生活';
        break;
    }
	case 13:
    {
        $type='五山·后勤服务';
        break;
    }
    case 14:
    {
        $type='五山·饭堂意见';
        break;
    }     
	case 20:
    {
        $type='大学城·所有提案';
        break;
    }	
    case 21:
    {
        $type='大学城·校园环境';
        break;
    }
	case 22:
    {
        $type='大学城·学生生活';
        break;
    }
	case 23:
    {
        $type='大学城·后勤服务';
        break;
    }
    case 24:
    {
        $type='大学城·饭堂意见';
        break;
    }
}
$typeID=$_GET['type'];//获得提案种类与页码
$page=$_GET['page'];
if($typeID==NULL||$page==NULL)
    header("location: http://1.quanyibuscut.sinaapp.com/quanxiaoyi/index.html");

$begin=($page-1)*10;
if($typeID==10)
{
    $sql="select * from proposal_main where type='11'||type='12'||type='13'||type='14' order by time desc,ID desc limit 10 offset $begin ";
    $sql2="select count(*) from proposal_main where type='11'||type='12'||type='13'||type='14'";
}else if($typeID==20)
{
    $sql="select * from proposal_main where type='21'||type='22'||type='23'||type='24' order by time desc,ID desc limit 10 offset $begin ";
    $sql2="select count(*) from proposal_main where type='21'||type='22'||type='23'||type='24'";    
}
else
{
	$sql="select * from proposal_main where type='$typeID' order by time desc,ID desc limit 10 offset $begin ";
    $sql2="select count(*) from proposal_main where type='$typeID'";
}
$arr2=SQL_turnarr(SQL_query($sql));//获得提案分页数据，转换成数组

$maxID=SQL_turnarr(SQL_query($sql2));
$maxID=$maxID[0][0];
$maxpage=(int)($maxID/10+1);//获得提案总条数与页码

?>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
		<link rel="stylesheet" type="text/css" href="../css/stylesheet.css">
		<title>华工权小益提案收集平台</title>
	</head>
	<body>
		<div class="header">
			<a href="../index.html"><img src="../img/newhead.jpg"></a>
		</div>
		<div class="clear"></div>
		<div class="typehead typehead1"><span><?php echo $type;?></span><a href="<?php if($_GET['type']<20) echo "wstype.html";else echo "dxctype.html"?>"><span style="float:right;">↰返回&nbsp;&nbsp;</span></a></div>

		<!-- 需要从数据库中读取此类消息的名称时间以及热度指数，然后直接就显示出来了。一下各类都很类似就不在其他的html文件里面注释了 -->
		<div class="prolist">
			<table>
				<tbody>
					<tr>
						<td>提案名称</td>
						<td>提案时间</td>
						<td>热度</td>
					</tr>
                    <?php 
						$i=0;
						for($j=0;$j<10;$j++)
                        {
                            $hot=$arr2[$i]['praise']+$arr2[$i]['score_time']*2;//计算热度指数，如果提案为NULL则也显示NULL
                            if($arr2[$i]['ID']==NULL)
                                $hot=NULL;
    						echo '
                            <tr>
                                <td>';
                            if($arr2[$i]['ID']!=NULL)
                                echo '
                                    <a href="detail.php?proposal_id='.$arr2[$i]['ID'].'&type='.$typeID.'">'.
                                        $arr2[$i]['title'].'
                                    </a>';
                            echo '
                                </td>
                                <td>'.time_show( $arr2[$i++]['time'] ).'</td>
                                <td>'.$hot.'</td>
                            </tr>';
                        }
                    ?>
				</tbody>
			</table>
            <div class="changepage">
				<a href="http://1.quanyibuscut.sinaapp.com/quanxiaoyi/templates/list.php?<?php $tmp=$page;if($tmp==1)$tmp+=1;echo 'type='.$typeID.'&page='.($tmp-1)?>"><div class="page">&lt;&lt;Prev</div></a>
				<a href="http://1.quanyibuscut.sinaapp.com/quanxiaoyi/templates/list.php?<?php if($page==$maxpage)$page-=1;echo 'type='.$typeID.'&page='.($page+1)?>"><div class="page page2">Next&gt;&gt;</div></a>
            </div>
		</div>
		<div class="clear"></div>
		<div class="wholecori">
			<div class="copyright">
				<span>Copyright © 2017 华南理工大学学生会权益部</span>
			</div>
			<div class="copyright">
				<span>Power by 无线电爱好者协会信息部</span>
			</div>
		</div>
		<div class="clear"></div>
	</body>
</html>